import request from '@/utils/http/uni-ajax';

/** 通用URL枚举 */
const Api = {
	/** 获取验证码图片 */
	VerifyCode: '/api/common/verifycode',
	/** 验证验证码的有效性，只作为前端Ajax验证，验证成功不移除验证码，验证码仍需传到后端进行再次验证 */
	CheckVerifyCode: '/api/common/checkverifycode',
	/** 获取系统信息 */
	SystemInfo: '/api/common/systeminfo',
}

/**
 * 获取验证码
 * @param mode 错误消息模型
 */
export async function getVerifyCode(mode = 'message') {
	const code = await request.get({
		url: Api.VerifyCode,
		requestOptions: {
			errorMessageMode: mode
		}
	});
	return code;
}

/**
 * 验证验证码的有效性，只作为前端Ajax验证，验证成功不移除验证码，验证码仍需传到后端进行再次验证
 * @param code 验证码字符串
 * @param id 验证码编号
 * @param mode 错误消息模型
 */
export function checkVerifyCode(code, id, mode = 'none') {
	return request.get({
		url: Api.CheckVerifyCode,
		query: {
			code: code,
			id: id
		},
		requestOptions: {
			errorMessageMode: mode
		}
	});
}

/**
 * 获取系统信息
 * @param mode 错误消息模型
 */
export function getSystemInfo(mode = 'none') {
	return request.get({
		url: Api.SystemInfo,
		requestOptions: {
			errorMessageMode: mode
		}
	});
}
